
/* 

Name : master_stickiness.do 
Authors: Martin, Méjean, Parenti
Last update: Sept. 2023 

*/

*** paths 

adopath + "D:\data\ado"


global datapath \\abra\CURRENT\CRT_PRJ_TRADENET\MMP\replication_restat\data // D:\temp\MEJEAN\MMP\replication  
global countrypath $datapath\country 
global firmpath $datapath\firm 
global sectorpath $datapath\sector 
global correspath $datapath\corres
global rspath $datapath\rs 
global tempath $datapath\temp 


global outputpath $datapath\exhibits_paper  //output
global dopath \\abra\CURRENT\CRT_PRJ_TRADENET\MMP\replication_restat\do // \\abra\CURRENT\CRT_PRJ_TRADENET\MMP\Do\restat_mmp_replic
global adop \\abra\CURRENT\CRT_PRJ_TRADENET\MMP\Do\restat_mmp_replic

adopath + "$adop"


*** global 
global product id_conc // name of the concorded product categories
global firstyear 1996
global lastyear 2006
global midyear 2002
global dataset transaction_all_id_conc$firstyear$lastyear // built in database_fromupload.do 
global countrysample "BE DE DK ES GB GR IE IT LU NL PT" 


*** auxilary programs 
set scheme s1color
cd $dopath
do id_group // too many observations => egen group doesn't work. This does the same job as egen group for large samples
do construct_base_4decile // in this program, we identify continous relationships and compute their duration 
do construct_base_totallength // in this program, we compute the duration of relationships irrespective of interruptions 
do estimate_bydecile // this is the program to estimate eq 3 of the paper 
do estimate_bydecileiso // this is the program to estimate eq 3 of the paper by country 
do construct_base_4duration // in this program, we identify continous relationships and compute their duration 
do sumstat_panel.do // compute stat desc

*** build the main dataset (transaction_all_id_conc.dta)

cd $datapath
do $dopath/upload_data.do
do $dopath/database_fromupload.do // also build table A.1

use $firmpath/$dataset, clear
rename importer buyer 
save $firmpath/$dataset, replace

global time_constraint  //"drop if firstyear_panel!=firstyear_sample" in a robustness, we add a constraint to deal with left censoring 
global time_constraint2 "drop if firstyear_sample>2004" // drop right-censored seller-buyer relationships
global dim_decile $product // we compute decile by product categories to better fit with the model, but in an robustness check, we compute it by $product & iso2 
global variant  _baseline // this is the name of the variant we consider  

cd $firmpath 
do $dopath/prepare_data_decile.do 
* average duration of seller-buyer trade, by product, destination and transaction size(decile) 

*** descriptive statistics (distribution of transactions and duration)

cd $firmpath 

do $dopath/figure_OA1_OA3_OA4.do  
do $dopath/figure_OA2.do   
do $dopath/figure_OA5.do  

do $dopath/table_OA2.do  
do $dopath/table_OA3.do   

*** baseline estimates of relationship stickiness

do $dopath/prepare_rs_baseline.do // baseline estimation of RS (include sensitivity checks on the specification -- alpha==1, no size control, country FE, duration) 

*** facts on the baseline measure of stickiness 

do $dopath/figure1.do // distribution of RS  
do $dopath/table3.do // correlation with product characteristics   
do $dopath/table4.do // microfoundations


*** checks for the online appendix 

do $dopath/table_OA6.do // corr with intrafirm trade  
do $dopath/table_OA7.do // institution and RS  
do $dopath/table_OA8.do  // gravity and RS 


*** robustness checks: alternative estimates of relationship stickiness 

do $dopath/prepare_rs_quintile.do // work with quintle rather than deciles 
do $dopath/prepare_rs_iso.do // decile by product AND iso2 + country specific estimates 
do $dopath/prepare_rs_topdecile.do // focus on top deciles
do $dopath/prepare_rs_transaction.do // number of transactions rather than months 
do $dopath/prepare_rs_totalduration.do // duration including interuptions  
do $dopath/prepare_rs_leftcensor.do // dealing with left censoring 
do $dopath/prepare_rs_4digit.do // 4-digit level  
do $dopath/prepare_rs_20112017.do // alternative time period  
do $dopath/prepare_rs_colombia.do // Colombian data 

cd $rspath
do $dopath/table_OA5.do // table 5 of the online appendix 


*** uncertainty and stickiness -- entry and exit 

do $dopath/prepare_base4reg.do // prepare the dataset for the analysis of the interplay btw stickiness and uncertainty
do $dopath/prepare_base4reg_nomne.do // same as above but excluding trad eflows between firms and countries where they have affilaites / HQ 
do $dopath/draws4bootstrap.do // make random draws used to compute bootstrapped s.e.  

do $dopath/table5.do // baseline results on uncertainty and stickiness 
do $dopath/figure2.do // baseline results on uncertainty and stickiness 
do $dopath/table_OA9_OA10.do // robustness for the appendix  
 
 
*** uncertainty and stickiness -- margin decomposition

do $dopath/prepare_base4margindecompo.do // prepare the dataset for the analysis of the impact of RS and uncertainty on the margin of growth 
do $dopath/table_OA11.do // table of regression used to compute figure 3 
do $dopath/figure3.do // impact of shocks on trade growth along the distribution of RS 
do $dopath/table_OA12.do
  





 

